 /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.knowledge.snomed.dao;

import co.edu.unal.bioingenium.kbmed.knowledge.dao.KnowledgeSourceDAO;
import co.edu.unal.bioingenium.kbmed.knowledge.snomed.vo.SnomedConcept;
import co.edu.unal.bioingenium.kbmed.knowledge.snomed.vo.SnomedDescriptor;
import co.edu.unal.bioingenium.kbmed.knowledge.snomed.vo.SnomedRelationship;
import co.edu.unal.bioingenium.kbmed.knowledge.vo.Concept;
import co.edu.unal.bioingenium.kbmed.knowledge.vo.Descriptor;
import co.edu.unal.bioingenium.kbmed.knowledge.vo.DescriptorData;
import co.edu.unal.bioingenium.kbmed.knowledge.vo.Relationship;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alejandro Riveros Cruz Riveros Cruz
 */
public class SnomedDAO extends KnowledgeSourceDAO {

    //
    private PreparedStatement getConceptsIds;
    //
    private PreparedStatement getConcepts;
    //
    private PreparedStatement getTermsByConceptId;
    //
    private PreparedStatement getTermsByDescriptorId;
    //
    private PreparedStatement getTermForDescriptorId;
    //
    private PreparedStatement getConceptIdByDescriptorId;
    //
    private PreparedStatement getDescriptorsByConceptId;
    //
    private PreparedStatement getDescriptorsIdsByConceptId;
    //
    private PreparedStatement getDescriptorsByDescriptorId;
    //
    private PreparedStatement getDescriptorDataByDescriptorId;
    //
    private PreparedStatement getTermsForConcept;
    //
    private PreparedStatement getRelatedConcepts_1TO2;
    //
    private PreparedStatement getRelatedConcepts_2TO1;
    //
    private PreparedStatement getRelatedConcepts_1TO2_;
    //
    private PreparedStatement getRelatedConcepts_2TO1_;
    //
    private PreparedStatement getCategories;
    //
    private PreparedStatement getConceptsInCategory;
    //
    private PreparedStatement getCategoriesForConcept;
    //
    private PreparedStatement getCategoryByConceptId;
    //
    private PreparedStatement insertConcept;
    //
    private PreparedStatement insertRelationship;
    //
    private PreparedStatement insertDescriptor;
    //
    private PreparedStatement updateConceptCategory;

    /**
     * @param:
     * @return:
     */
    public SnomedDAO() {
        super();
    }
    //TODO put the language code automatic

    /**
     * Method to init the specific prepared statements
     */
    @Override
    public void initStatements() throws SQLException {
        //Init the specific querys

        //For concept ids
        getConceptsIds = connection.prepareStatement("SELECT conceptID FROM concepts;");

        //For vo concepts
        getConcepts = connection.prepareStatement("SELECT conceptId,fullySpecifiedName,category,numTokens FROM concepts;");

        //For collections in wich terms are related with conceptId
        getTermsByConceptId = connection.prepareStatement("SELECT conceptID, term FROM descriptors;");
        getTermForDescriptorId = connection.prepareStatement("SELECT term FROM descriptors WHERE descriptionID=?;");

        //For collections in wich terms are related with conceptId
        getTermsByDescriptorId = connection.prepareStatement("SELECT descriptionID, term FROM descriptors;");

        //For collections in wich descriptorIds are related with conceptId
        getConceptIdByDescriptorId = connection.prepareStatement("SELECT descriptionId,conceptID FROM descriptors;");

        //For collections in wich descriptors are related with conceptId
        getDescriptorsByConceptId = connection.prepareStatement("SELECT c.conceptID,d.descriptionID,d.term,d.numTokens "
                + "FROM descriptors d,concepts c "
                + "WHERE c.conceptID=d.conceptID;");
        //For collections in wich descriptorsIds are related with conceptId
        getDescriptorsIdsByConceptId = connection.prepareStatement("SELECT c.conceptID,d.descriptionID "
                + "FROM descriptors d,concepts c "
                + "WHERE c.conceptID=d.conceptID;");

        //For collections in wich descriptors are related with descriptorId
        getDescriptorsByDescriptorId = connection.prepareStatement("SELECT descriptionID,conceptID,term,numTokens FROM descriptors d;");
        getDescriptorDataByDescriptorId = connection.prepareStatement("SELECT c.conceptID,d.descriptionID,d.term,c.category,d.numTokens "
                + "FROM descriptors d,concepts c "
                + "WHERE c.conceptID=d.conceptID;");
        //to get Term related with a especific concept
        getTermsForConcept = connection.prepareStatement("SELECT descriptionID,term FROM descriptors WHERE conceptID=?;");

        //To query the relationships
        getRelatedConcepts_1TO2 = connection.prepareStatement("SELECT conceptID1 FROM relationships WHERE conceptID2=?;");
        getRelatedConcepts_2TO1 = connection.prepareStatement("SELECT conceptID2 FROM relationships WHERE conceptID1=?;");
        getRelatedConcepts_1TO2_ = connection.prepareStatement("SELECT conceptID1 FROM relationships WHERE conceptID2=? AND relationshipType=?;");
        getRelatedConcepts_2TO1_ = connection.prepareStatement("SELECT conceptID2 FROM relationships WHERE conceptID1=? AND relationshipType=?;");

        //To query the categories
        getCategories = connection.prepareStatement("SELECT DISTINCT category FROM concepts;");
        getConceptsInCategory = connection.prepareStatement("SELECT conceptID FROM concepts WHERE category=?;");
        getCategoriesForConcept = connection.prepareStatement("SELECT category FROM concepts WHERE conceptID=?;");
        getCategoryByConceptId = connection.prepareStatement("SELECT conceptID,category FROM concepts;");

        //To do insertions
        insertConcept = connection.prepareStatement("INSERT INTO concepts(conceptID,conceptStatus,fullySpecifiedName,CTV3ID,SNOMEDID,isPrimitive,category,numTokens) VALUES (?,?,?,?,?,?,?,?);");
        insertDescriptor = connection.prepareStatement("INSERT INTO descriptors(descriptionID,descriptionStatus,conceptID,term,initialCapitalStatus,descriptionType,languageCode,numTokens) VALUES (?,?,?,?,?,?,?,?);");
        insertRelationship = connection.prepareStatement("INSERT INTO relationships(relationshipID,conceptID1,relationshipType,conceptID2,characteristicType,refinability,relationshipGroup) VALUES (?,?,?,?,?,?,?);");

        //Other
        updateConceptCategory = connection.prepareStatement("UPDATE concept SET category=? WHERE conceptID=?;");
    }

    @Override
    public Set<String> getConceptsIds() {
        try {
            Set<String> conceptsIDs = new HashSet<String>();
            ResultSet resultSet = getConceptsIds.executeQuery();
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException sqle) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, sqle);
        }
        return null;
    }

    @Override
    public Set<String> getConceptsIds(Map<String, String> criteria) {
        StringBuilder completeCriteria = new StringBuilder();
        Set<String> conceptsIDs = new HashSet<String>();
        String currentKey;
        int criteriaCount = 0;
        for (Iterator<String> it = criteria.keySet().iterator(); it.hasNext();) {
            currentKey = it.next();
            if (criteriaCount < criteria.size() - 1) {
                completeCriteria.append(currentKey).append("=").append("'").append(criteria.get(currentKey)).append("'").append(" AND ");
            } else {
                completeCriteria.append(currentKey).append("=").append("'").append(criteria.get(currentKey)).append("'");
            }
            criteriaCount++;
        }
        try {
            ResultSet resultSet = doQuery("SELECT conceptID FROM concepts WHERE " + completeCriteria.toString() + ";");
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, "Error in filter " + completeCriteria.toString(), ex);
        }
        return null;
    }

    @Override
    public Set<Concept> getConcepts() {
        try {
            Set<Concept> conceptSet = new HashSet<Concept>();
            Concept concept;
            ResultSet resultSet = getConcepts.executeQuery();
            while (resultSet.next()) {
                concept = new Concept();
                concept.setConceptId(resultSet.getString(1).intern());
                concept.setDescription(resultSet.getString(2));
                concept.setCategory(resultSet.getString(3).intern());
                concept.setNumTokens(resultSet.getShort(4));
                conceptSet.add(concept);
            }
            return conceptSet;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<Concept> getConcepts(Map<String, String> criteria) {
        StringBuilder completeCriteria = new StringBuilder();
        Set<Concept> conceptSet = new HashSet<Concept>();
        Concept concept;
        String currentKey;
        int criteriaCount = 0;
        for (Iterator<String> it = criteria.keySet().iterator(); it.hasNext();) {
            currentKey = it.next();
            if (criteriaCount < criteria.size() - 1) {
                completeCriteria.append(currentKey).append("=").append("'").append(criteria.get(currentKey)).append("'").append(" AND ");
            } else {
                completeCriteria.append(currentKey).append("=").append("'").append(criteria.get(currentKey)).append("'");
            }
            criteriaCount++;
        }
        try {
            ResultSet resultSet = doQuery("SELECT conceptId,fullySpecifiedName,category,numTokens FROM concepts WHERE " + completeCriteria.toString() + ";");
            while (resultSet.next()) {
                concept = new Concept();
                concept.setConceptId(resultSet.getString(1));
                concept.setDescription(resultSet.getString(2));
                concept.setCategory(resultSet.getString(3));
                concept.setNumTokens(resultSet.getShort(4));
                conceptSet.add(concept);
            }
            return conceptSet;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, "Error in filter " + completeCriteria.toString(), ex);
        }
        return null;
    }

    @Override
    public Map<String, Concept> getConceptbyConceptId() {
        Set<Concept> concepts = getConcepts();
        Map<String, Concept> map = new HashMap<String, Concept>();
        for (Concept concept : concepts) {
            map.put(concept.getConceptId(), concept);
        }
        return map;
    }

    @Override
    public Map<String, Set<String>> getTermsByConceptId() {
        try {
            Map<String, Set<String>> hashMap = new HashMap<String, Set<String>>();
            ResultSet resultSet = getTermsByConceptId.executeQuery();
            String conceptID, term;
            Set<String> terms;
            while (resultSet.next()) {
                conceptID = resultSet.getString(1);
                term = resultSet.getString(2);
                if (hashMap.containsKey(conceptID)) {
                    hashMap.get(conceptID).add(term);
                } else {
                    terms = new HashSet<String>();
                    terms.add(term);
                    hashMap.put(conceptID, terms);
                }
            }
            return hashMap;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Map<String, String> getTermsByDescriptorId() {
        try {
            Map<String, String> map = new HashMap<String, String>();
            ResultSet resultSet = getTermsByDescriptorId.executeQuery();
            while (resultSet.next()) {
                map.put(resultSet.getString(1).intern(), resultSet.getString(2));
            }
            return map;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public String getTermForDescriptorId(String descriptorId) {
        try {
            getTermForDescriptorId.setString(1, descriptorId);
            ResultSet resultSet = getTermForDescriptorId.executeQuery();
            if (resultSet.next()) {
                return resultSet.getString(1);
            }
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Map<String, String> getConceptIdByDescriptorId() {
        try {
            Map<String, String> map = new HashMap<String, String>();
            ResultSet resultSet = getConceptIdByDescriptorId.executeQuery();
            while (resultSet.next()) {
                map.put(resultSet.getString(1).intern(), resultSet.getString(2).intern());
            }
            return map;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Map<String, Set<Descriptor>> getDescriptorsByConceptId() {
        try {
            Map<String, Set<Descriptor>> map = new HashMap<String, Set<Descriptor>>();
            Set<Descriptor> descriptorsSet;
            Descriptor descriptor;
            String conceptId;
            ResultSet allDescriptors = getDescriptorsByConceptId.executeQuery();
            while (allDescriptors.next()) {
                conceptId = allDescriptors.getString(1);
                descriptor = new Descriptor();
                descriptor.setDescriptionId(allDescriptors.getString(2));
                descriptor.setConceptId(conceptId);
                descriptor.setTerm(allDescriptors.getString(3));
                descriptor.setNumTokens(allDescriptors.getShort(4));
                if (map.containsKey(conceptId)) {
                    map.get(conceptId).add(descriptor);
                } else {
                    descriptorsSet = new HashSet<Descriptor>();
                    descriptorsSet.add(descriptor);
                    map.put(conceptId, descriptorsSet);
                }
            }
            return map;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Map<String, Set<String>> getDescriptorsIdsByConceptId() {
        try {
            Map<String, Set<String>> map = new HashMap<String, Set<String>>();
            Set<String> descriptorsSet;
            String conceptId;
            ResultSet allDescriptors = getDescriptorsIdsByConceptId.executeQuery();
            while (allDescriptors.next()) {
                conceptId = allDescriptors.getString(1);
                if (map.containsKey(conceptId)) {
                    map.get(conceptId).add(allDescriptors.getString(2));
                } else {
                    descriptorsSet = new HashSet<String>();
                    descriptorsSet.add(allDescriptors.getString(2));
                    map.put(conceptId, descriptorsSet);
                }
            }
            return map;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Map<String, Descriptor> getDescriptorsByDescriptorId() {
        try {
            Map<String, Descriptor> map = new HashMap<String, Descriptor>();
            Descriptor descriptor;
            ResultSet resultSet = getDescriptorsByDescriptorId.executeQuery();
            while (resultSet.next()) {
                descriptor = new Descriptor();
                descriptor.setDescriptionId(resultSet.getString(1).intern());
                descriptor.setConceptId(resultSet.getString(2).intern());
                descriptor.setTerm(resultSet.getString(3));
                descriptor.setNumTokens(resultSet.getShort(4));
                map.put(descriptor.getDescriptionId(), descriptor);
            }
            return map;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Map<String, String> getTermsForConcept(String conceptId) {
        try {
            Map<String, String> terms = new HashMap<String, String>();
            getTermsForConcept.setString(1, conceptId);
            ResultSet resultSet = getTermsForConcept.executeQuery();
            while (resultSet.next()) {
                terms.put(resultSet.getString(1).intern(), resultSet.getString(2));
            }
            return terms;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<String> getRelatedConcepts_1TO2(String concept2ID) {
        try {
            Set<String> conceptsIDs = new HashSet<String>();
            getRelatedConcepts_1TO2.setString(1, concept2ID);
            ResultSet resultSet = getRelatedConcepts_1TO2.executeQuery();
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<String> getRelatedConcepts_1TO2(String concept2ID, String relationshipType) {
        try {
            Set<String> conceptsIDs = new HashSet<String>();
            getRelatedConcepts_1TO2_.setString(1, concept2ID);
            getRelatedConcepts_1TO2_.setString(2, relationshipType);
            ResultSet resultSet = getRelatedConcepts_1TO2_.executeQuery();
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<String> getRelatedConcepts_2TO1(String concept1ID) {
        try {
            Set<String> conceptsIDs = new HashSet<String>();
            getRelatedConcepts_2TO1.setString(1, concept1ID);
            ResultSet resultSet = getRelatedConcepts_2TO1.executeQuery();
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<String> getRelatedConcepts_2TO1(String concept1ID, String relationshipType) {
        try {
            Set<String> conceptsIDs = new HashSet<String>();
            getRelatedConcepts_2TO1_.setString(1, concept1ID);
            getRelatedConcepts_2TO1_.setString(2, relationshipType);
            ResultSet resultSet = getRelatedConcepts_2TO1_.executeQuery();
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<String> getCategories() {
        try {
            Set<String> categories = new HashSet<String>();
            ResultSet resultSet = getCategories.executeQuery();
            while (resultSet.next()) {
                categories.add(resultSet.getString(1));
            }
            return categories;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public Set<String> getConceptsInCategory(String category) {
        try {
            Set<String> conceptsIDs = new HashSet<String>();
            getConceptsInCategory.setString(1, category);
            ResultSet resultSet = getConceptsInCategory.executeQuery();
            while (resultSet.next()) {
                conceptsIDs.add(resultSet.getString(1));
            }
            return conceptsIDs;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public String getCategoryForConcept(String conceptID) {
        try {
            getCategoriesForConcept.setString(1, conceptID);
            ResultSet resultSet = getCategoriesForConcept.executeQuery();
            if (resultSet.next()) {
                return resultSet.getString(1);
            }
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public String getCategoryDescription(String categoryID) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Map<String, String> getCategoryByConceptId() {
        try {
            Map<String, String> terms = new HashMap<String, String>();
            ResultSet resultSet = getCategoryByConceptId.executeQuery();
            while (resultSet.next()) {
                terms.put(resultSet.getString(1).intern(), resultSet.getString(2).intern());
            }
            return terms;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    @Override
    public void insertConcept(Concept concept) {
        SnomedConcept snomedConcept = (SnomedConcept) concept;
        try {
            insertConcept.setString(1, snomedConcept.getConceptId());
            insertConcept.setByte(2, snomedConcept.getStatus());
            insertConcept.setString(3, snomedConcept.getDescription());
            insertConcept.setString(4, snomedConcept.getCTV3ID());
            insertConcept.setString(5, snomedConcept.getSNOMEDID());
            insertConcept.setByte(6, snomedConcept.getIsPrimitive());
            insertConcept.setString(7, snomedConcept.getCategory());
            insertConcept.setShort(8, snomedConcept.getNumTokens());
            insertConcept.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, "Error inserting concept with id " + snomedConcept.getConceptId(), ex);
        }
    }

    @Override
    public void insertDescriptor(Descriptor descriptor) {
        SnomedDescriptor snomedDescriptor = (SnomedDescriptor) descriptor;
        try {
            insertDescriptor.setString(1, snomedDescriptor.getDescriptionId());
            insertDescriptor.setByte(2, snomedDescriptor.getStatus());
            insertDescriptor.setString(3, snomedDescriptor.getConceptId());
            insertDescriptor.setString(4, snomedDescriptor.getTerm());
            insertDescriptor.setBoolean(5, snomedDescriptor.isInitialCapitalStatus());
            insertDescriptor.setByte(6, snomedDescriptor.getDescriptionType());
            insertDescriptor.setString(7, snomedDescriptor.getLanguageCode());
            insertDescriptor.setShort(8, snomedDescriptor.getNumTokens());
            insertDescriptor.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, "Error inserting descriptor with id " + snomedDescriptor.getDescriptionId(), ex);
        }
    }

    @Override
    public void insertRelationShip(Relationship relationship) {
        SnomedRelationship snomedRelationship = (SnomedRelationship) relationship;
        try {
            insertRelationship.setString(1, snomedRelationship.getRelationshipID());
            insertRelationship.setString(2, snomedRelationship.getConceptID1());
            insertRelationship.setString(3, snomedRelationship.getRelationshipType());
            insertRelationship.setString(4, snomedRelationship.getConceptID2());
            insertRelationship.setByte(5, snomedRelationship.getCharacteristicType());
            insertRelationship.setByte(6, snomedRelationship.getRefinability());
            insertRelationship.setByte(7, snomedRelationship.getRelationshipGroup());
            insertRelationship.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, "Error inserting relationship with id " + snomedRelationship.getRelationshipID(), ex);
        }
    }

    /**
     * @param:
     * @param category 
     * @return:
     * @param conceptID 
     */
    public void updateConceptCategory(String conceptID, String category) {
        try {
            updateConceptCategory.setString(1, category);
            updateConceptCategory.setString(2, conceptID);
            updateConceptCategory.executeUpdate();
        } catch (SQLException sqle) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, sqle);
        }
    }

    @Override
    public Map<String, DescriptorData> getDescriptorDataByDescriptorId() {
        try {
            Map<String, DescriptorData> map = new HashMap<String, DescriptorData>();
            DescriptorData descriptorData;
            //c.conceptID,d.descriptionID,d.term,c.category,d.numTokens "
            ResultSet resultSet = getDescriptorDataByDescriptorId.executeQuery();
            while (resultSet.next()) {
                descriptorData = new DescriptorData(resultSet.getString(1).intern(), resultSet.getString(2).intern(), resultSet.getString(3), resultSet.getString(4).intern(), resultSet.getShort(5));
                map.put(descriptorData.getDescriptorId(), descriptorData);
            }
            return map;
        } catch (SQLException ex) {
            Logger.getLogger(SnomedDAO.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;

    }
}
